<div class="bs-callout bs-callout-info">
    <h4>Add entry</h4>
    <p><a href="<?php echo base_url()?>admin/entry">+ Back</a></p>
</div>

<form class="form-horizontal" role="form" method="POST">
    <div class="form-group">
        <label for="categoryid" class="col-sm-2 control-label">Category</label>
        <div class="col-sm-5">
            <select id="parent" class="form-control">
                <?php
                    foreach($categories as $key=>$value){
                ?>
                <option value="<?php echo $value['id']?>" <?php if($value['id'] == $parent[$data['categoryid']]) echo 'selected'?>><?php echo $value['categoryname']?></option>
                <?php
                    }
                ?>
            </select>
        </div>
        <div class="col-sm-5">
            <select id="categoryid" name="categoryid" class="form-control">
                
            </select>
        </div>
    </div>
    
    <div class="form-group">
        <label for="title" class="col-sm-2 control-label">Title</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="title" placeholder="Title" name="title" value="<?php echo $data['title'];?>" />
        </div>
    </div>
    
    <div class="form-group">
        <label for="slug" class="col-sm-2 control-label">Slug</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="slug" placeholder="Slug" name="slug" value="<?php echo $data['slug'];?>" />
        </div>
    </div>
    
    <div class="form-group">
        <label for="description" class="col-sm-2 control-label">Description</label>
        <div class="col-sm-10">
            <textarea class="form-control" id="description" placeholder="Description" name="description" ><?php echo $data['description'];?></textarea>
        </div>
    </div>
    
    <div class="form-group">
        <label for="image" class="col-sm-2 control-label">Image</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="image" placeholder="Image" name="image" value="<?php echo $data['image'];?>" />
        </div>
        <div class="col-sm-2">
            <input type="button" id="btnSelectImg" class="btn btn-primary" value="Browse server" />
        </div>
    </div>
    
    <div class="form-group">
        <label for="content1" class="col-sm-2 control-label">Content</label>
        <div class="col-sm-10">
            <textarea class="form-control" id="content1" placeholder="Content" name="content" ><?php echo $data['content'];?></textarea>
        </div>
    </div>
    
    <div class="form-group">
        <label for="views" class="col-sm-2 control-label">Views</label>
        <div class="col-sm-10">
            <input type="number" class="form-control" id="views" placeholder="Views" name="views" value="<?php echo $data['views'];?>" />
        </div>
    </div>
    
    <div class="form-group">
        <label for="statuss" class="col-sm-2 control-label">Status</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="statuss" placeholder="Status" name="statuss" value="<?php echo $data['statuss'];?>" />
        </div>
    </div>
    
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-default">Save</button>
        </div>
    </div>
</form>
<script type="text/javascript">
$(function() {				    				    
    var editor = CKEDITOR.replace('content1',
    {
        filebrowserBrowseUrl : '<?php echo base_url()."library/ckfinder/ckfinder.html"; ?>',
        filebrowserImageBrowseUrl : '<?php echo base_url()."library/ckfinder/ckfinder.html?Type=Images";?>',
        filebrowserFlashBrowseUrl : '<?php echo base_url()."library/ckfinder/ckfinder.html?Type=Flash" ?>',
        filebrowserUploadUrl : '<?php echo base_url()."library/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files"?>',
        filebrowserImageUploadUrl : '<?php echo base_url()."library/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images";?>',
        filebrowserFlashUploadUrl : '<?php echo base_url()."ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash";?>',
        filebrowserWindowWidth : '800',
        filebrowserWindowHeight : '480'
    });
    CKFinder.setupCKEditor( editor, "<?php echo base_url().'library/ckfinder/'?>" );
})
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnSelectImg").click(function () {
            var finder = new CKFinder();
            finder.selectActionFunction = function (fileUrl) {
                $('#image').val(fileUrl);
            };
            finder.popup();
        });
    });
 </script>
 <script>
$("#parent").change(function(){
    //The combo box
    var sel = $(this);
    //Selected value
    var value = sel.val();
    //Fetch the images
    $.get("<?php echo base_url().'ajax/getSubs'?>",{id: value, selected: <?php echo $data['categoryid']?>}, function(data){
        //Add images to the document
        $("#categoryid").html(data);
    });
})
$("#parent").change();
</script>